<template>
  <div id="hot">
    <div class="hot-header">
      <div>热门</div>
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          {{ dropItems[dropSelected]
          }}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="nfts">NFT</el-dropdown-item>
          <el-dropdown-item command="collections">合集</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <div class="hot-tip">{{ showTip[dropSelected] }}</div>
    <transition name='hot-router'>
      <router-view></router-view>
    </transition>
  </div>
</template>

<script>
export default {
  name: "Hot",
  data() {
    return {
      // 下拉框
      dropItems: ["NFT", "合集"],
      showTip: ["最热门的 NFT 商品", "当下最热门的合集"],
      dropSelected: 0,
    };
  },

  watch: {
    "$route.path": {
      immediate: true,
      handler(newValue) {
        if (newValue == "/hot/nfts") {
          this.dropSelected = 0;
        } else if (newValue == "/hot/collections") {
          this.dropSelected = 1;
        }
      },
    },
  },

  methods: {
    handleCommand(command) {
      if (command == "nfts") {
        this.$router.push("/hot/nfts");
      } else if (command == "collections") {
        this.$router.push("/hot/collections");
      }
    },
  },
};
</script>

<style lang='less' scoped>
// 路由切换动画
.hot-router-enter,
.hot-router-leave-to {
  opacity: 0;
}
.hot-router-enter-active,
.hot-router-leave-active {
  transition: all 0.5s ease;
}
#hot {
  padding: 20px 0;
  .hot-header {
    margin-left: calc(1.5% + 40px);
    font-size: 20px;
    display: flex;
    align-items: center;
    font-weight: bold;
    .el-dropdown-link {
      font-size: 20px;
    }
  }
  .hot-tip {
    margin-left: calc(1.5% + 40px);
    font-size: 15px;
    margin-top: 10px;
  }
}
</style>